//
//  LGCommissionViewController.m
//  LuxuryGoods
//
//  Created by 刘星辰 on 2018/5/22.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "LGCommissionViewController.h"
#import "LGCommodityInfoView.h"
#import "LGImageManagerIO.h"
#import "LGCommodityProtocolView.h"
#import "LGHintViewController.h"
#import "LGCommodityInfoView.h"
#import "LGCommissionCell.h"
#import "UIViewController+Album.h"

@interface LGCommissionViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIButton *recycleBtn;
@end

@implementation LGCommissionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"商品信息";
    self.view.backgroundColor = UIColorFromRGB(0xF5F5F5);
  
    [self addNavRightBtn];
    
    [self.recycleBtn setCornerRadius:self. recycleBtn.height / 2.0];
    UIImage *image = [LGImageManagerIO createGradualColorImage:self.recycleBtn.size startColor:LOW_COLOR endColor:HIGH_COLOR];
    [self.recycleBtn setBackgroundImage:image forState:UIControlStateNormal];
    
    [self addProtocolView];
    
    self.tableView.backgroundColor = UIColorFromRGB(0xF5F5F5);
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
#pragma mark nav上右侧按钮
- (void)addNavRightBtn
{
    UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"寄卖流程" forState:UIControlStateNormal];
    button.titleLabel.font =  FONT(15);
    [button setTitleColor:TEXT_COLOR_1 forState:UIControlStateNormal];
    [button addTarget:self action:@selector(gotoRecycleWebView) forControlEvents:UIControlEventTouchUpInside];
    [button sizeToFit];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    
}

- (void)gotoRecycleWebView
{
    
}

- (void)addProtocolView
{
    LGCommodityProtocolView *view = [LGCommodityProtocolView createFromXib];
    [self.view addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.recycleBtn.superview.mas_top).offset(0);
        make.width.offset(SCREEN_WIDTH);
        make.height.offset(30);
        make.left.offset(0);
    }];
}

- (IBAction)recycleAction:(id)sender
{
    LGHintViewController *vc = [LGHintViewController createFromXib];
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark -
#pragma mark tableView的Delegate和DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //创建复用单元格
    //创建xib复用单元格
    static NSString * ID = @"LGCommissionCell";
    LGCommissionCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"LGCommissionCell" owner:self options:nil] firstObject];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    
    WeakObj(self)
    //浏览照片的流程
    cell.checkPhoto = ^{
        [selfWeak gotoRecycleWebView];
    };
    
    //选择照片
    cell.choosePhoto = ^(LGCommissionCell *cell) {
        [selfWeak pickerManyImageCount:12 - cell.dataArray.count handle:^(NSArray<PHAsset *> *images) {
            [cell addPhotoAndRefreshUIWith:images];
            
        }];
    };
    
    //view
    cell.browsePhoto = ^(LGCommissionCell *cell, NSInteger index) {
        
        [selfWeak gotoSelectedAssets:cell.dataArray index:index];
    };
    
    return cell;
}

////预估高度
//- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 524;
//}

//预估高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 530;
}


@end
